package com.waiting.mq.listener;

import com.waiting.mq.dao.OrderDao;
import com.waiting.mq.entity.Order;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class OverdueListener {


    @Resource
    private OrderDao orderDao;

    @RabbitListener(queues = "q.order.dlx")
    public void overdue(Integer id) {

        Order order = orderDao.queryById(id);
        if (order.getStatus() == 0) {
            System.out.println("此訂單已過期: " + id);
            order.setStatus(2);
            orderDao.update(order);
        }

    }

}
